package com.winhxd.b2c.search.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;

@Configuration
public class ESConfig {
    @Value("${elasticsearch.uris}")
    private String[] uris;

    @Bean
    public RestHighLevelClient restHighLevelClient() {
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(
                        Arrays.stream(uris).map(HttpHost::create).toArray(HttpHost[]::new)
                )
        );
        return client;
    }
}
